All files / vidly/models customer.js

71.43% Statements 5/7
100% Branches 0/0
0% Functions 0/1
71.43% Lines 5/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 342x 2x   2x                                                         2x 2x
const Joi = require('joi');
const mongoose = require('mongoose');
 
const Customer = mongoose.model('Customer', new mongoose.Schema({
  name: {
    type: String,
    required: true,
    minlength: 5,
    maxlength: 50
  },
  isGold: {
    type: Boolean,
    default: false
  },
  phone: {
    type: String,
    required: true,
    minlength: 5,
    maxlength: 50
  }
}));
 
function validateCustomer(customer) {
  const schema = {
    name: Joi.string().min(5).max(50).required(),
    phone: Joi.string().min(5).max(50).required(),
    isGold: Joi.boolean()
  };
 
  return Joi.validate(customer, schema);
}
 
exports.Customer = Customer; 
exports.validate = validateCustomer;